import {
  addScene,
  queryDIYOrgTree,
  queryOrgList,
  queryScene,
  queryTreeOrgList,
  removeScene,
  updateScene,
} from '@/services/strategy/scene';
import { queryLevel, } from '@/services/bnsConfig/level';
export default {
  namespace: 'scene',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm: {},

    detailData: {
      userList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    }

  },

  effects: {
    * queryList({payload}, {call, put}) {
      const response = yield call(queryScene, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    * add({payload, callback}, {call, put}) {
      const response = yield call(addScene, payload);
      yield put({
        type: 'saveadd',
        payload: response,
      });
      if (callback) callback(response);
    },
    * remove({payload, callback}, {call, put}) {
      const response = yield call(removeScene, payload);
      yield put({
        type: 'saveremove',
        payload: response,
      });
      if (callback) callback(response);
    },
    * update({payload, callback}, {call, put}) {
      const response = yield call(updateScene, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    },
    * queryLevel({payload, callback}, {call, put}) {
      const response = yield call(queryLevel, payload);
      if (callback) callback(response);
    },
    * getTree({payload, callback}, {call, put}) {
      const response = yield call(queryTreeOrgList, payload);
      yield put({
        type: 'saveTree',
        payload: response,
      });
      if (callback) callback(response);
    },
    * getList({payload, callback}, {call, put}) {
      const response = yield call(queryOrgList, payload);
      yield put({
        type: 'saveList',
        payload: response,
      });
      if (callback) callback(response);
    },
    * diyOrgTree({payload, callback}, {call, put}) {
      const response = yield call(queryDIYOrgTree, payload);
      yield put({
        type: 'diyList',
        payload: response,
      });
      if (callback) callback(response);
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
    detailData(state, action) {
      return {
        ...state,
        detailData: action.payload,
      };
    },
  },
};
